//
//  DMScrollView.m
//  Gunz
//
//  Created by Joggy on 16/1/23.
//  Copyright © 2016年 NUPT. All rights reserved.
//

#import "DMView.h"

static integer_t dmStatus = 0;
//static BOOL isOneDMShow = false;
//static BOOL isTwoDMShow = false;
//static BOOL isThreeDMShow = false;
//static BOOL isFourDMShow = false;

@implementation DMView

- (instancetype)initWithFrame:(CGRect)frame andMenu:(NSArray *)menu {
    self = [super initWithFrame:frame];
    sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    for(int i = 0; i < menu.count; i++) {
        UIButton *but = [UIButton buttonWithType:UIButtonTypeSystem];
        but.frame = CGRectMake(0, i*DMButtonHeight, frame.size.width, DMButtonHeight);
        NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:menu[i]];
        NSRange titleRange = {0, title.length};
        [title addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.3 green:0.32 blue:0.34 alpha:1] range:titleRange];
        [title addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font14] range:titleRange];
        [but setAttributedTitle:title forState:UIControlStateNormal];
        [sv addSubview:but];
    }
    sv.backgroundColor = [UIColor clearColor];
    sv.showsVerticalScrollIndicator = false;
    //调整视图的大小
    if(menu.count*DMButtonHeight <= self.frame.size.height) {
        CGRect temp = self.frame;
        temp.size.height = menu.count*DMButtonHeight;
        self.frame = temp;
    }
    //调整sv的内容大小
    sv.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    sv.contentSize = CGSizeMake(self.frame.size.width, menu.count*DMButtonHeight);
    [self addSubview:sv];
    self.backgroundColor = [UIColor whiteColor];
    self.layer.shadowColor = [UIColor colorWithRed:0.53 green:0.53 blue:0.53 alpha:1].CGColor;
    self.layer.shadowRadius = 2;
    self.layer.shadowOffset = CGSizeMake(1, 1);
    self.layer.shadowOpacity = 1;
    self.layer.masksToBounds = false;
    return self;
}

+(integer_t)DMStatus {
    return dmStatus;
}

+(void)setDMStatus:(integer_t)status {
    dmStatus = status;
}

-(void)dismiss {
    [self removeFromSuperview];
}

@end
